package com.hyk.commonLib.common.dialogView.base;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.dylanc.viewbinding.base.ViewBindingUtil;
import com.hyk.commonLib.common.activity.BaseActivity;
import com.lxj.xpopup.core.CenterPopupView;

import lombok.Getter;

public class CenterPopupViewExt<DATA_BINDING extends ViewDataBinding> extends CenterPopupView {
    @Getter
    protected DATA_BINDING dataBinding;

    public CenterPopupViewExt(@NonNull Context context) {
        super(context);
        dataBinding = ViewBindingUtil.inflateWithGeneric(this, LayoutInflater.from(context), centerPopupContainer, false);
        if (context instanceof BaseActivity<?>) {
            dataBinding.setLifecycleOwner(((BaseActivity<?>) context));
        }
    }

    @Override
    protected void addInnerContent() {
        contentView = dataBinding.getRoot();
        LayoutParams params = (LayoutParams) contentView.getLayoutParams();
        params.gravity = Gravity.CENTER;
        centerPopupContainer.addView(contentView, params);
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        applyTheme();
    }

}
